//
//  CZEmoticonPackage.swift
//  EmoticonsDemo
//
//  Created by Summer on 2017/12/19.
//  Copyright © 2017年 Summer. All rights reserved.
//

import UIKit

/// 表情包模型
@objcMembers
class CZEmoticonPackage: NSObject {
    
    /// 分组名
    var groupName: String?
    
    /// 目录，从目录加载 info.plist 可以创建表情模型数组
    var directory: String? {
        didSet {
            
            // 当设置目录时，从目录加载plist
            guard let directory = directory,
                let path = Bundle.main.path(forResource: "HMEmoticon.bundle", ofType: nil),
                let bundle = Bundle(path: path),
                let infoPath = bundle.path(forResource: "info.plist", ofType: nil, inDirectory: directory),
                let array = NSArray(contentsOfFile: infoPath) as? [[String: String]],
                let models = NSArray.yy_modelArray(with: CZEmoticon.self, json: array) as? [CZEmoticon] else {
                return
            }
            
            for m in models {
                m.directory = directory
            }
            
            emoticons += models
        }
    }
    
    /// 表情模型数组
    /// 使用懒加载，可以避免后续的解包
    lazy var emoticons = [CZEmoticon]()
    
    override var description: String {
        return yy_modelDescription()
    }
    
}
